INSERT INTO  TRASPARENZA

select 'T31',BOLLETTA,'','TOTALE ONERI DIVERSI NON SOGGETTI IVA','','','','','','','',SUM(TOTALE),'',null FROM(
SELECT '',BOLLETTA,'','','','','','','','','',SUM(TOTALE) totale,'' FROM TRASPARENZA 
WHERE RIGA IN ('T27','T28','T29') AND (ALI_IVA IS NULL or ali_iva = 0) GROUP BY BOLLETTA
union
SELECT '',BOLLETTA,'','','','','','','','','',0 totale,'' FROM TRASPARENZA GROUP BY BOLLETTA)
group by bolletta




